<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Master extends MY_Controller {

    public function __construct() {
        parent::__construct();

        // (sementara)
        $config['hostname'] = "localhost";
        $config['username'] = "root";
        $config['password'] = "";
        $config['database'] = "homepage_ps";
        $config['dbdriver'] = "mysql";
        $config['dbprefix'] = "";
        $config['pconnect'] = FALSE;
        $config['db_debug'] = TRUE;
        $config['cache_on'] = FALSE;
        $config['cachedir'] = "";
        $config['char_set'] = "utf8";
        $config['dbcollat'] = "utf8_general_ci";
        $this->load->database($config);

        $this->_data["menuHL"] = "Home";
        $this->_data["navTitle"] = "Master Data";
        $this->_data["navData"] = array(
            array("title" => "Regional", "url" => "master/regional", "sub" => array(
                    array("title" => "Region", "url" => "master/regional/reg"),
                    array("title" => "Provinsi", "url" => "master/regional/prov"),
                    array("title" => "Kabupaten", "url" => "master/regional/kab"),
                    array("title" => "Kecamatan", "url" => "master/regional/kec"),
                    array("title" => "Desa", "url" => "master/regional/desa"),
                )),
            array("title" => "Indikator", "url" => "master/indikator"),
            array("title" => "Mitra", "url" => "master/partner"),
            array("title" => "Kategori Buletin", "url" => "master/katbuletin"),
        );
        $this->addBreadCrumb("Home", site_url("home"));
        $this->addBreadCrumb("Master Data", site_url("master"));
    }

    protected function _renderPage($page) {
        $this->_data["page"] = $page;
        parent::_renderPage("master/base");
    }

    public function index() {
        $this->regional();
    }

    public function regional($subpage = "reg") {
        $this->addBreadCrumb("Regional", "master/regional");

        switch ($subpage) {
            case "reg" :
                $this->addBreadCrumb("Regional", "master/regional/reg");
                $this->_data["pageTitle"] = "Master Data Region";	
				$qq =$this->db->query('select * from region');	
				$this->_data["arrayreg"] = $qq->result();
                break;
            case "prov" :
                $this->addBreadCrumb("Provinsi", "master/regional/prov");
                $this->_data["pageTitle"] = "Master Data Provinsi";
				$qq =$this->db->query('select * from provinsi');	
				$this->_data["arrayreg"] = $qq->result();
				
                break;
            case "kab" :
                $this->addBreadCrumb("Provinsi", "master/regional/kab");
                $this->_data["pageTitle"] = "Master Data Kabupaten";
				$qq =$this->db->query('select * from kabupaten');	
				$this->_data["arrayreg"] = $qq->result(); 
                break;
            case "kec" :
                $this->addBreadCrumb("Provinsi", "master/regional/kec");
                $this->_data["pageTitle"] = "Master Data Kecamatan";
				$qq =$this->db->query('select * from kecamatan limit 50');	
				$this->_data["arrayreg"] = $qq->result();				
                break;
            case "desa" :
                $this->addBreadCrumb("Provinsi", "master/regional/des");
                $this->_data["pageTitle"] = "Master Data Desa";
				$qq =$this->db->query('select * from perdesaan limit 50');	
				$this->_data["arrayreg"] = $qq->result();				
                break;
        }
		$this->_data["page2"] = $subpage;
        $this->_renderPage("regional");
    }
	
	public function add_reg($p="") {
 
        switch ($p) {
            case "reg" :
			$this->_data["pageTitle"] = "Master Data Mitra PS Add New Region";
			$this->addBreadCrumb("Add Region", "master/addreg");	
			$this->_data["add_page"] = "reg";
			$this->_renderPage("add_reg");
			break;
			case "prov" :
			$this->_data["pageTitle"] = "Master Data Mitra PS Add New Propinsi";
			$this->addBreadCrumb("Add Propinsi", "master/addreg");	
			$this->_data["add_page"] = "prov";
			$qq =$this->db->query('select * from region');	
			$this->_data["arrayreg"] = $qq->result();			
			$this->_renderPage("add_reg");
			break;
			case "kab" :
			$this->_data["pageTitle"] = "Master Data Mitra PS Add New Kabupaten";
			$this->addBreadCrumb("Add Kabupaten", "master/addreg");	
			$this->_data["add_page"] = "kab";
			$qq =$this->db->query('select * from provinsi');	
			$this->_data["arrayreg"] = $qq->result();						
			$this->_renderPage("add_reg");
			break;
			case "kec" :
			$this->_data["pageTitle"] = "Master Data Mitra PS Add New Kecamatan";
			$this->addBreadCrumb("Add Kecamatan", "master/addreg");	
			$this->_data["add_page"] = "kec";
			$qq =$this->db->query('select * from kabupaten');	
			$this->_data["arrayreg"] = $qq->result();									
			$this->_renderPage("add_reg");
			break;
			case "desa" :
			$this->_data["pageTitle"] = "Master Data Mitra PS Add New Desa";
			$this->addBreadCrumb("Add Desa", "master/addreg");	
			$this->_data["add_page"] = "desa";
			$qq =$this->db->query('select * from kecamatan');	
			$this->_data["arrayreg"] = $qq->result();				
			$this->_renderPage("add_reg");
			break;			
			
		}

	}
	
	public function edit_reg($p="",$id="") {
		
        switch ($p) {
            case "reg" :
			$qq =$this->db->query('select * from region where id =' .$id);	
			$this->_data["regobj"] = $qq->row();
			$this->_data["pageTitle"] = "Master Data Mitra PS Edit Region";
			$this->addBreadCrumb("Edit Region", "master/editreg");	
			$this->_data["edit_page"] = "reg";
			$this->_renderPage("edit_reg");
			break;
			case "prov" :
			$qq =$this->db->query('select * from provinsi where id =' .$id);	
			$this->_data["regobj"] = $qq->row();
			$qp =$this->db->query('select * from region');	
			$this->_data["arrayreg"] = $qp->result();			
			$this->_data["pageTitle"] = "Master Data Mitra PS Edit Propinsi";
			$this->addBreadCrumb("Edit Propinsi", "master/editreg");	
			$this->_data["edit_page"] = "prov";
			$this->_renderPage("edit_reg");
			break;
			case "kab" :
			$qq =$this->db->query('select * from kabupaten where id =' .$id);	
			$this->_data["regobj"] = $qq->row();
			$qp =$this->db->query('select * from provinsi');	
			$this->_data["arrayreg"] = $qp->result();				
			$this->_data["pageTitle"] = "Master Data Mitra PS Edit Kabupaten";
			$this->addBreadCrumb("Edit Kabupaten", "master/editreg");	
			$this->_data["edit_page"] = "kab";
			$this->_renderPage("edit_reg");
			break;
			case "kec" :
			$qq =$this->db->query('select * from kecamatan where id =' .$id);	
			$this->_data["regobj"] = $qq->row();
			$qp =$this->db->query('select * from kabupaten');	
			$this->_data["arrayreg"] = $qp->result();			
			$this->_data["pageTitle"] = "Master Data Mitra PS Edit Kecamatan";
			$this->addBreadCrumb("Edit Kecamatan", "master/editreg");	
			$this->_data["edit_page"] = "kec";
			$this->_renderPage("edit_reg");
			break;
			case "desa" :
			$qq =$this->db->query('select * from perdesaan where id =' .$id);	
			$this->_data["regobj"] = $qq->row();
			$qp =$this->db->query('select * from kecamatan');	
			$this->_data["arrayreg"] = $qp->result();			
			$this->_data["pageTitle"] = "Master Data Mitra PS Edit Desa";
			$this->addBreadCrumb("Edit Desa", "master/editreg");	
			$this->_data["edit_page"] = "desa";
			$this->_renderPage("edit_reg");
			break;									
		}		
		
				
	}
	
	public function add_regional($p="") {
 
        switch ($p) {
            case "reg" :
			$this->_data["pageTitle"] = "Master Data Mitra PS Add New Region";
			$this->addBreadCrumb("Add Region", "master/addreg");	
			$this->_data["add_page"] = "reg";
			$data=array(
			"code"=>$this->input->post('code'),
			"display_name"=>$this->input->post('display_name'),
			"summary"=>$this->input->post('summary'),
			"latitude"=>$this->input->post('latitude'),
			"longlatitude"=>$this->input->post('longlatitude')
			);
			$this->db->insert('region', $data);
			break;
			case "prov" :
			$this->_data["pageTitle"] = "Master Data Mitra PS Add New Propinsi";
			$this->addBreadCrumb("Add Propinsi", "master/addreg");	
			$this->_data["add_page"] = "prov";
			$data=array(
			"code"=>$this->input->post('code'),
			"display_name"=>$this->input->post('display_name'),
			"region_id"=>$this->input->post('region_id'),
			"summary"=>$this->input->post('summary'),
			"latitude"=>$this->input->post('latitude'),
			"longlatitude"=>$this->input->post('longlatitude')
			);
			$this->db->insert('provinsi', $data);			
			break;
			case "kab" :
			$this->_data["pageTitle"] = "Master Data Mitra PS Add New Kabupaten";
			$this->addBreadCrumb("Add Kabupaten", "master/addreg");	
			$this->_data["add_page"] = "kab";
			$data=array(
			"code"=>$this->input->post('code'),
			"display_name"=>$this->input->post('display_name'),
			"provinsi_id"=>$this->input->post('provinsi_id'),
			"is_tertinggal"=>$this->input->post('is_tertinggal'),
			"is_tertinggal84"=>$this->input->post('is_tertinggal84'),			
			"summary"=>$this->input->post('summary'),
			"latitude"=>$this->input->post('latitude'),
			"longlatitude"=>$this->input->post('longlatitude')
			);
			$this->db->insert('kabupaten', $data);
			break;
			case "kec" :
			$this->_data["pageTitle"] = "Master Data Mitra PS Add New Kecamatan";
			$this->addBreadCrumb("Add Kecamatan", "master/addreg");	
			$this->_data["add_page"] = "kec";
			$data=array(
			"code"=>$this->input->post('code'),
			"display_name"=>$this->input->post('display_name'),
			"kabupaten_id"=>$this->input->post('kabupaten_id'),
			"summary"=>$this->input->post('summary'),
			"latitude"=>$this->input->post('latitude'),
			"longlatitude"=>$this->input->post('longlatitude')
			);
			$this->db->insert('kecamatan', $data);			
			break;
			case "desa" :
			$this->_data["pageTitle"] = "Master Data Mitra PS Add New Desa";
			$this->addBreadCrumb("Add Desa", "master/addreg");	
			$this->_data["add_page"] = "desa";
			$data=array(
			"code"=>$this->input->post('code'),
			"display_name"=>$this->input->post('display_name'),
			"kecamatan_id"=>$this->input->post('kecamatan_id'),
			"summary"=>$this->input->post('summary'),
			"latitude"=>$this->input->post('latitude'),
			"longlatitude"=>$this->input->post('longlatitude')
			);
			$this->db->insert('perdesaan', $data);			
			break;			
			
			
		}
		redirect("master/regional/".$p);
	}

	public function edit_regional($p="") {
 
        switch ($p) {
            case "reg" :
			$this->_data["add_page"] = "reg";
			$data=array(
			"code"=>$this->input->post('code'),
			"display_name"=>$this->input->post('display_name'),
			"summary"=>$this->input->post('summary'),
			"latitude"=>$this->input->post('latitude'),
			"longlatitude"=>$this->input->post('longlatitude')
			);
			$this->db->where('id', $this->input->post('id'));
			$this->db->update('region', $data);				
			break;
			case "prov" :
			$this->_data["add_page"] = "prov";
			$data=array(
			"code"=>$this->input->post('code'),
			"display_name"=>$this->input->post('display_name'),
			"region_id"=>$this->input->post('region_id'),
			"summary"=>$this->input->post('summary'),
			"latitude"=>$this->input->post('latitude'),
			"longlatitude"=>$this->input->post('longlatitude')
			);
			$this->db->where('id', $this->input->post('id'));
			$this->db->update('provinsi', $data);						
			break;
			case "kab" :
			$this->_data["add_page"] = "kab";
			$data=array(
			"code"=>$this->input->post('code'),
			"display_name"=>$this->input->post('display_name'),
			"provinsi_id"=>$this->input->post('provinsi_id'),
			"is_tertinggal"=>$this->input->post('is_tertinggal'),
			"is_tertinggal84"=>$this->input->post('is_tertinggal84'),			
			"summary"=>$this->input->post('summary'),
			"latitude"=>$this->input->post('latitude'),
			"longlatitude"=>$this->input->post('longlatitude')
			);
			$this->db->where('id', $this->input->post('id'));
			$this->db->update('kabupaten', $data);				
			break;
			case "kec" :
			$this->_data["add_page"] = "kec";
			$data=array(
			"code"=>$this->input->post('code'),
			"display_name"=>$this->input->post('display_name'),
			"kabupaten_id"=>$this->input->post('kabupaten_id'),
			"summary"=>$this->input->post('summary'),
			"latitude"=>$this->input->post('latitude'),
			"longlatitude"=>$this->input->post('longlatitude')
			);
			$this->db->where('id', $this->input->post('id'));
			$this->db->update('kecamatan', $data);			
			break;
			case "desa" :
			$this->_data["add_page"] = "desa";
			$data=array(
			"code"=>$this->input->post('code'),
			"display_name"=>$this->input->post('display_name'),
			"kecamatan_id"=>$this->input->post('kecamatan_id'),
			"summary"=>$this->input->post('summary'),
			"latitude"=>$this->input->post('latitude'),
			"longlatitude"=>$this->input->post('longlatitude')
			);
			$this->db->where('id', $this->input->post('id'));
			$this->db->update('perdesaan', $data); 			
			break;			
			
			
		}
		redirect("master/regional/".$p);
	}
	
	
	public function del_reg($p="",$id="") {
 
        switch ($p) {
            case "reg" :
			$this->_data["add_page"] = "reg";
			$this->db->where('id', $id);
			$this->db->delete('region'); 
			break;
			case "prov" :
			$this->_data["add_page"] = "prov";
			$this->db->where('id', $id);
			$this->db->delete('provinsi'); 			
			break;
			case "kab" :
			$this->_data["add_page"] = "kab";
			$this->db->where('id', $id);
			$this->db->delete('kabupaten'); 			
			break;
			case "kec" :
			$this->_data["add_page"] = "kec";
			$this->db->where('id', $id);
			$this->db->delete('kecamatan'); 
			break;
			case "desa" :
			$this->_data["add_page"] = "desa";
			$this->db->where('id', $id);
			$this->db->delete('perdesaan'); 
			break;			
			
			
		}
		redirect("master/regional/".$p);
	}
		
	
    public function partner() {
        $this->_data["pageTitle"] = "Master Data Mitra PS";
        $this->addBreadCrumb("Mitra", "master/partner");
        $this->_renderPage("partner");
    }

    public function indikator() {
        $this->_data["pageTitle"] = "Master Data Indikator";
        $this->addBreadCrumb("Indikator", "master/indikator");
        $this->_renderPage("indikator");
    }

    public function katbuletin() {
        $this->_data["pageTitle"] = "Master Data Kategori Buletin";
        $this->addBreadCrumb("Kategori Buletin", "master/katbuletin");
        $this->_renderPage("katbuletin");
    }

}
